<meta charset="UTF-8">
<style type="text/css">
    /*body,html{width:100%;height:100%;background:#000;padding:0;margin:0;overflow-x:hidden;overflow-y:hidden}*/
    /**{margin:0;border:0;padding:0;text-decoration:none}*/
    #stats{position:fixed;top:5px;left:10px;font-size:12px;color:#fdfdfd;z-index:2147483647;text-shadow:1px 1px 1px #000, 1px 1px 1px #000}
    /*#dplayer{position:inherit}*/
</style>
<div id="dplayer"></div>

<div id="stats"></div>
<script src="//cdn.jsdelivr.net/npm/vconsole@latest"></script>
<script src="https://cdn.jsdelivr.net/npm/cdnbye@latest/dist/hlsjs-p2p-engine.min.js"></script>
<!--<script src="./hlsjs-p2p-engine.js"></script>-->
<script src="https://cdn.jsdelivr.net/npm/hls.js@latest"></script>
<!--<script src="https://cdn.jsdelivr.net/npm/cbplayer2@latest"></script>-->
<script src="https://cdn.jsdelivr.net/npm/cbplayer2@0.11.0"></script>
<script src="https://cdn.jsdelivr.net/npm/swarmcloud-hls-sw@latest"></script>
<script>
    var vConsole = new VConsole();
    var _peerId = '', _peerNum = 0, _totalP2PDownloaded = 0, _totalP2PUploaded = 0;
    // var url = 'https://wowza.peer5.com/live/smil:bbb_abr.smil/playlist.m3u8'
    var url = 'https://wowza.peer5.com/live/smil:bbb_abr.smil/chunklist_b591000.m3u8'

    var options = {
        container: document.getElementById('dplayer'),
        autoplay: true,
        live: true,
        // playState: true,
        video: {
            // url: 'https://pull.asia.uurtc.com/tzuchi/anyrtcej8mzJr0U1ZT_cycb360/playlist.m3u8?wsSecret=07a0b9d8eacfc3400c75e9ffc2303c7d&wsTime=1594177497&keeptime=86400',
            // url: 'https://www.nmgxwhz.com:65/20200107/17hTnjxI/index.m3u8',
            url
        },
        pluginOptions: {
            hls: {
                debug: false,
                p2pConfig: {
                    logLevel: 'none',
                    live: true,
                    // Other p2pConfig options provided by CDNBye
                    // https://docs.cdnbye.com/#/API
                }
            },
            ios: {
                logLevel: 'debug',
                nativePlaybackOnly: true,    // key step: only enabled when MSE is not supported
            }
        },
    }

    var dp = new CBPlayer(options);

    dp.on('stats', function (stats) {
        _totalP2PDownloaded = stats.totalP2PDownloaded;
        _totalP2PUploaded = stats.totalP2PUploaded;
        updateStats();
    })
    dp.on('peerId', function (peerId) {
        _peerId = peerId;
    })
    dp.on('peers', function (peers) {
        _peerNum = peers.length;
        updateStats();
    });

    function updateStats() {
        var text = 'CDNBye P2P正在为您加速' + (_totalP2PDownloaded/1024).toFixed(2)
            + 'MB 已分享' + (_totalP2PUploaded/1024).toFixed(2) + 'MB' + ' 连接节点' + _peerNum + '个';
        document.getElementById('stats').innerText = text

    }

    // setTimeout(() => {
    //     options.live = true;
    //     options.video = {
    //         url,
    //         // url: 'https://www.nmgxwhz.com:65/20200107/17hTnjxI/index.m3u8',
    //     }
    //     // dp.switchVideo(,)
    //     dp = new CBPlayer(options);
    //     dp.play()
    // }, 30000)
    //
    // setTimeout(() => {
    //     dp.switchVideo({
    //         url,
    //     },)
    //     dp.play()
    // }, 80000)

    // setTimeout(() => {
    //
    //     dp.destroy()
    //     dp = new CBPlayer({
    //         container: document.getElementById('dplayer'),
    //         autoplay: true,
    //         live: false,
    //         video: {
    //             // url: 'https://pull.asia.uurtc.com/tzuchi/anyrtcej8mzJr0U1ZT_cycb360/playlist.m3u8?wsSecret=07a0b9d8eacfc3400c75e9ffc2303c7d&wsTime=1594177497&keeptime=86400',
    //             // url: 'https://www.nmgxwhz.com:65/20200107/17hTnjxI/index.m3u8',
    //             url: 'http://v.live.hndt.com/video/20200317/9411f6c1f11b44888294d47d73107641/cloudv-transfer/555555555po0q1sn5556526553738q1r_73ac26e878d047498fa906ef9e913036_0_4.m3u8',
    //         },
    //         pluginOptions: {
    //             hls: {
    //                 debug: false,
    //                 p2pConfig: {
    //                     logLevel: 'none',
    //                     // live: true,
    //                     // Other p2pConfig options provided by CDNBye
    //                     // https://docs.cdnbye.com/#/API
    //                 }
    //             }
    //         },
    //     });
    //
    // }, 10000)

</script>
